package logic

import (
	"context"
	"zc2/userrpc/userrpc"

	"zc2/api/internal/svc"
	"zc2/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddGoodsLogic) AddGoods(req *types.AddGoodsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	goods, err := l.svcCtx.UserRpc.AddGoods(l.ctx, &userrpc.AddGoodsRequest{
		Title:  req.Title,
		Des:    req.Des,
		Price:  req.Price,
		Userid: int64(req.Userid),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    "500",
		}, nil
	}
	return &types.Response{
		Message: "商品发布成功",
		Data:    goods,
		Code:    "200",
	}, nil
}
